/**
 * Copyright (c) 时间, Tal.Ben 袁东昊 (ydonghao2@gmail.com).
 *
 * 版权
 */
package com.talben.soudian.api;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.CookieStore;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONObject;

import android.content.Context;

import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.talben.soudian.AppContext;
import com.talben.soudian.TDevice;

/**
 * @Title: SouDianAPI.java
 * @Package com.talben.soudian.api
 * @Description: 网络交互接口
 * @author Tal.Ben
 * @date 2015年5月23日 上午9:21:54
 * @version v1.0
 */
public class SouDianAPI {

	/**
	 * @Title: login
	 * @Description: 登陆
	 * @param @param username
	 * @param @param password
	 * @param @param handler    设定文件
	 * @return void    返回类型
	 * @throws
	 */
	public static void login(String username, String password,
            AsyncHttpResponseHandler handler) {
        RequestParams params = new RequestParams();
        params.put("account", username);
        params.put("password", password);
        ApiHttpClient.postDirect(UrlConnect.LOGIN_URL, params, handler);
    }
	
	public static void logout(AsyncHttpResponseHandler handler) {
        RequestParams params = new RequestParams();
        ApiHttpClient.postDirect(UrlConnect.LOGOUT, params, handler);
    }
	
	/**
	 * @Title: register
	 * @Description: 注册
	 * @param @param uname
	 * @param @param phone
	 * @param @param email
	 * @param @param password
	 * @param @param mac
	 * @param @param handler    设定文件
	 * @return void    返回类型
	 * @throws
	 */
	public static void register(String uname,String phone,
			String email, String password, String mac ,
            AsyncHttpResponseHandler handler) {
		RequestParams params = new RequestParams();
        params.put("account", phone);
        params.put("username", uname);
        params.put("email", email);
        params.put("phone", phone);
        params.put("mac", mac);
        params.put("password", password);
        params.put("master", TDevice.getMaster(AppContext.getInstance()));
        ApiHttpClient.postDirect(UrlConnect.REGISTER_UTL, params, handler);
	}
	
	
	/**
	 * @Title: forgetPassword
	 * @Description: T找回密码
	 * @param phone
	 * @param email
	 * @param handler    设定文件
	 * @return void    返回类型
	 * @throws
	 */
	public static void forgetPassword(String phone, String email,
            AsyncHttpResponseHandler handler){
		RequestParams params = new RequestParams();
        params.put("email", email);
        params.put("phone", phone);
        ApiHttpClient.postDirect(UrlConnect.CHANGE_PASSWORD_PWD, params, handler);
	}
	
	/**
	 * @Title: getMyInformation
	 * @Description: 获取用户信息
	 * @param uid
	 * @param context
	 * @param handler    设定文件
	 * @return void    返回类型
	 * @throws
	 */
	public static void getMyInformation(String uid, AsyncHttpResponseHandler handler){
		RequestParams params = new RequestParams();
        params.put("account", uid);
        ApiHttpClient.postDirect(UrlConnect.ACCOUNT_URL, params, handler);
	}
	
	/**
	 * @Title: changePwd
	 * @Description: 修改密码
	 * @param oldpwd
	 * @param newpwd
	 * @param confirmpwd
	 * @param syncHttpResponseHandler    设定文件
	 * @return void    返回类型
	 * @throws
	 */
	public static void changePwd(String oldpwd, String newpwd, 
			AsyncHttpResponseHandler handler){
		RequestParams params = new RequestParams();
		params.put("oldpass", oldpwd);
		params.put("newpass", newpwd);
		ApiHttpClient.postDirect(UrlConnect.CHANGE_PASSWORD_PWD, params, handler);
	}
	
	/**
	 * @Title: getApkList
	 * @Description: 获取apk列表
	 * @param catalog
	 * @param page
	 * @param handler    设定文件
	 * @return void    返回类型
	 * @throws
	 */
	public static void getApkList(int catalog, int page, int type,
			AsyncHttpResponseHandler handler ) {
		RequestParams params = new RequestParams();
		params.put("page", page + 1);
		params.put("rows", AppContext.PAGE_SIZE);
		params.put("type", type + 1 );
		ApiHttpClient.postDirect(UrlConnect.APPLIST_URL, params, handler);
	}
	
	/**
	 * @Title: getGiftList
	 * @Description: 礼品列表
	 * @param account
	 * @param catalog
	 * @param page
	 * @param handler    设定文件
	 * @return void    返回类型
	 * @throws
	 */
	public static void getGiftList(int catalog, int page,
			AsyncHttpResponseHandler handler){
		RequestParams params = new RequestParams();
		params.put("page", page + 1);
		params.put("rows", AppContext.PAGE_SIZE);
		params.put("type", "0");
		ApiHttpClient.postDirect(UrlConnect.GIFT_URL, params, handler);
		
	}
	
	/**
	 * @Title: getScore
	 * @Description: 获取积分
	 * @param account
	 * @param appid
	 * @param handler   设定文件
	 * @return void   返回类型
	 * @throws
	 */
	public static void getScore(String account ,String appid ,
			AsyncHttpResponseHandler handler){
		RequestParams params = new RequestParams();
		params.put("account", account);
		params.put("appid", appid);
		ApiHttpClient.postDirect(UrlConnect.GET_SCORE, params, handler);
	}
	
	/**
	 * @Title: getGiftLog
	 * @Description: 获取礼品清单
	 * @param handler    设定文件
	 * @return void    返回类型
	 * @throws
	 */
	public static void getGiftLog(AsyncHttpResponseHandler handler){
		RequestParams params = new RequestParams();
		params.put("page", "1");
		params.put("rows", "10");
		ApiHttpClient.postDirect(UrlConnect.GET_GIFTLOG, params, handler);
	}
	
	/**
	 * @Title: getMasterInfo
	 * @Description: 获取师徒消息
	 * @param handler    设定文件
	 * @return void    返回类型
	 * @throws
	 */
	public static void getMasterInfo(AsyncHttpResponseHandler handler){
		RequestParams params = new RequestParams();
		ApiHttpClient.postDirect(UrlConnect.GET_MASTER_INFO, params, handler);
	}
	
	/**
	 * @Title: checkUpdate
	 * @Description: 版本升级
	 * @param handler    设定文件
	 * @return void    返回类型
	 * @throws
	 */
	public static void checkUpdate(AsyncHttpResponseHandler handler){
		RequestParams params = new RequestParams();
		ApiHttpClient.postDirect(UrlConnect.GET_VERSION, params, handler);
	}
	
	/**
	 * @Title: getAppZone
	 * @Description: apk zone
	 * @param handler    设定文件
	 * @return void    返回类型
	 * @throws
	 */
	public static void getAppZone(AsyncHttpResponseHandler handler){
		RequestParams params = new RequestParams();
		ApiHttpClient.postDirect(UrlConnect.GET_APP_ZONE, params, handler);
	}
	
	public static void cashGift(String account,String giftId,String number,AsyncHttpResponseHandler handler){
		RequestParams params = new RequestParams();
		params.put("account", account);
		params.put("id", giftId);
		params.put("number", number);
		ApiHttpClient.postDirect(UrlConnect.GET_GIFT, params, handler);
	}
	
}

